package com.talkweb.newproject.admin.sysacl.service;


import com.talkweb.newproject.admin.sysacl.dao.SysAclDao;
import com.talkweb.newproject.admin.sysacl.dto.SysAclDTO;
import com.talkweb.newproject.api.model.admin.SysAclParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by qsf on 2019/4/19.
 */
@Service
public class SysAclService {
    @Autowired
    private SysAclDao sysAclDao;

    public Boolean insertSysAcl(SysAclDTO sysAclDTO) throws Exception {
        sysAclDao.deleteSysAclByRoleId(sysAclDTO);
        int count=sysAclDao.insertSysAcl(sysAclDTO.getRoleId(),sysAclDTO.getResourceids());
        return count > 0;

    }

    /**
     *删除
     */
    @Transactional(rollbackFor = {Exception.class})
    public void deleteSysAcl(String ids) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("ids",ids);
        sysAclDao.deleteSysAcl(params);
    }

    @Transactional(rollbackFor = {Exception.class})
    public void updateSysAcl(SysAclDTO sysAclDTO) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("dto",sysAclDTO);
        sysAclDao.updateSysAcl(params);
    }

    public SysAclDTO querySysAclByPrimaryKey(String id) throws Exception{
        SysAclDTO result = sysAclDao.findSysAclByPrimaryKey(id);
        if(result==null) {
            result = new SysAclDTO();
        }
        return result;
    }

    public List<SysAclDTO> searchSysAcl(SysAclParam params) throws Exception{
        Map<String,Object> map= new HashMap<>();
        map.put("dto",params);
        return sysAclDao.searchSysAcl(map);

    }

    public SysAclDTO queryLikeSysAcl(SysAclDTO sysAcl) throws Exception{
        Map<String,Object> params  = new HashMap<>();
        params.put("dto",sysAcl);
        return sysAclDao.queryLikeSysAcl(params);
    }
}
